package com.css.devops.rest;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.css.devops.domain.PipelineMonitor;
import com.css.devops.domain.vo.PipelineMonitorQueryCriteria;
import com.css.devops.service.DevopsPipelineMonitor;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "Devops：查询构建任务Pipeline的各个阶段的详情")
@RestController
@RequestMapping("${devops-context}/pipelineMonitor")
public class DevopsPipelineMonitorResource {

	@Resource(name = "${devops.service.pipeline-monitor}")
	private DevopsPipelineMonitor devopsPipelineMonitor;
	
	@ApiOperation(value = "查询pipeline构建列表")
	@PostMapping("queryPipelineMonitor")
	public ResponseEntity<List<PipelineMonitor>> queryPipelineMonitor(@RequestBody PipelineMonitorQueryCriteria pipelineMonitorQueryCriteria) {
		List<PipelineMonitor> pipelineMonitors = null;
		try {
			pipelineMonitors = devopsPipelineMonitor.queryPipelineMonitor(pipelineMonitorQueryCriteria);
		}catch (Exception e) {
			return ResponseEntity.status(HttpStatus.NOT_FOUND).body(pipelineMonitors);
		}
		return ResponseEntity.ok(pipelineMonitors);
	}
}
